const http = require('http');

// 测试轮播图API
function testBannersAPI() {
  const options = {
    hostname: 'localhost',
    port: 3000,
    path: '/cosmetic/banners',
    method: 'GET'
  };

  const req = http.request(options, (res) => {
    let data = '';
    
    res.on('data', (chunk) => {
      data += chunk;
    });
    
    res.on('end', () => {
      try {
        const response = JSON.parse(data);
        console.log('✅ 轮播图API测试结果:');
        console.log('状态码:', res.statusCode);
        console.log('数据条数:', response.data ? response.data.length : 0);
        if (response.data && response.data.length > 0) {
          console.log('第一张图片URL:', response.data[0].image);
          console.log('是否包含新图片:', response.data[0].image.includes('images.unsplash.com'));
        }
      } catch (error) {
        console.log('❌ 解析响应失败:', error);
      }
    });
  });

  req.on('error', (error) => {
    console.log('❌ 轮播图API请求失败:', error.message);
  });

  req.end();
}

// 测试商品API
function testProductsAPI() {
  const options = {
    hostname: 'localhost',
    port: 3000,
    path: '/cosmetic/products',
    method: 'GET'
  };

  const req = http.request(options, (res) => {
    let data = '';
    
    res.on('data', (chunk) => {
      data += chunk;
    });
    
    res.on('end', () => {
      try {
        const response = JSON.parse(data);
        console.log('\n✅ 商品API测试结果:');
        console.log('状态码:', res.statusCode);
        if (response.data && response.data.热门) {
          console.log('热门商品数量:', response.data.热门.length);
          if (response.data.热门.length > 0) {
            console.log('第一个商品图片URL:', response.data.热门[0].image);
            console.log('是否包含新图片:', response.data.热门[0].image.includes('images.unsplash.com'));
          }
        }
      } catch (error) {
        console.log('❌ 解析响应失败:', error);
      }
    });
  });

  req.on('error', (error) => {
    console.log('❌ 商品API请求失败:', error.message);
  });

  req.end();
}

console.log('🔍 开始测试API数据...\n');
testBannersAPI();
setTimeout(testProductsAPI, 1000);
